/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tcloudclient.actionManager;

import api.action.ActionTypeEnum;
import api.action.crates.Client.NewUpdateFolderCrate;
import tcloudclient.Utils;
import java.io.File;

/**
 *
 * @author Tomas
 */
public class DeleteActionExecutor implements ExecuteActionInterface<NewUpdateFolderCrate> {

    @Override
    public boolean isSupported(ActionTypeEnum actionType) {
        return actionType == ActionTypeEnum.DELETE_FILE || actionType == ActionTypeEnum.DELETE_FOLDER;
    }

    @Override
    public void execute(NewUpdateFolderCrate actionData, FireActionExecuteInterface event) {
        if(event.canActionExecute(actionData.getPath(), actionData.getVersion(), tcloudclient.actionManager.ActionTypeClientEnum.DELETE)){
            File file = new File(Utils.generatePaht(actionData.getPath()));
            if(file.delete()){
                event.actionExecuted(actionData.getPath(), 0l, tcloudclient.actionManager.ActionTypeClientEnum.DELETE);
            }
        }
    }
    
}
